<script lang="ts" setup>
import { ref, nextTick } from 'vue'
import wjzs from '@/components/wjzs.vue'
import gdglService from '@/api/gdgl'
import { ElMessage } from 'element-plus'
import axios from '@/request/http'
import { useMainStore } from '@/store/main'

const store = useMainStore()
/*
 * 打开弹框
 */
//
const dialogVisible = ref<boolean>(false)
// 入参
const wjzsRef = ref<InstanceType<typeof wjzs>>()
// 生命周期
const openDialog = (val: string[]) => {
  getAjgddjbxh(val)
  dialogVisible.value = true
}
/**
 * 获取归档顺序
 */
const url = ref<string>('')
const getAjgddjbxh = (val: string[]) => {
  const params = {
    gdbhList: val,
  }
  gdglService
    .getAjgddjbxh(params)
    .then((res) => {
      if (res) {
        const xh = res.data as unknown as string
        const dwmc = store.userInfo.dwmc
        url.value = `${window.IPCONFIG}/api/gdgl/getAjgddjb?gddjbxh=${xh}&dwmc=${dwmc}`
        nextTick(() => {
          wjzsRef.value!.init()
        })
      }
    })
    .catch((err) => {
      !err.isError && ElMessage({ type: 'warning', message: err.message })
    })
}

defineExpose({ openDialog })
</script>
<template>
  <el-dialog v-model="dialogVisible" title="归档登记表" width="80%" :close-on-click-modal="false">
    <div class="dialog-box">
      <!--文件-->
      <wjzs ref="wjzsRef" wjlx="word" :url="url" />
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<style lang="scss" scoped>
.dialog-box {
  width: 100%;
  height: 70vh;
}
</style>
